package com.test.fundible.fundible_05_process;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.test.fundible.R;
import com.test.fundible.fundible_01_launcher.App_fundibleShow_fundibleCustomize;
import com.test.fundible.Othe_fundiblersInfo;


public class Bin_fundibledAcco_fundibleuntChannelDialog_Fr extends Dialog {

    private final String mobile_fundible;

    private final Runnable denyRunnable_fundible, addAccountRunnable_fundible;

    private ImageView logoIv_fundible;
    private TextView channelTv_fundible, mobileTv_fundible;
    private View cancelBtn_fundible, okBtn_fundible;

    public Bin_fundibledAcco_fundibleuntChannelDialog_Fr(@NonNull Context context, String mobile, Runnable denyRunnable, Runnable addAccountRunnable) {
        super(context);
        this.mobile_fundible = mobile;
        this.denyRunnable_fundible = denyRunnable;
        this.addAccountRunnable_fundible = addAccountRunnable;
    }

    @SuppressLint("ClickableViewAccessibility")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_fundible_bind_account_channel_fr);

        getWindow().setBackgroundDrawableResource(R.color.transparent);
        setCanceledOnTouchOutside(false);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        logoIv_fundible = findViewById(R.id.dbacfa_iv_logo);
        channelTv_fundible = findViewById(R.id.dbacfa_tv_channel);
        mobileTv_fundible = findViewById(R.id.dbacfa_tv_mobile);
        cancelBtn_fundible = findViewById(R.id.dbacfa_btn_cancel);
        okBtn_fundible = findViewById(R.id.dbacfa_btn_ok);

        TextView textTv = findViewById(R.id.dbacfa_tv_text);
        textTv.setText(getContext().getString(R.string.bind_channel_dialog_desc1, Othe_fundiblersInfo.getInstance_fundible().getChannel_fundible()));

        findViewById(R.id.dbacfa_view_out).setOnClickListener(v -> dismiss());
        findViewById(R.id.dbacfa_view_in).setOnTouchListener((v, event) -> true);

        initView_fundible();
    }

    @SuppressLint("SetTextI18n")
    private void initView_fundible(){

        String channel = Othe_fundiblersInfo.getInstance_fundible().getChannel_fundible();

        //获取图标
        Bitmap logoBm = App_fundibleShow_fundibleCustomize.getInstance_fundible().getChannelLogoByValue_fundible(channel);
        if (logoBm!=null) logoIv_fundible.setImageBitmap(logoBm);

        mobileTv_fundible.setText(mobile_fundible);
        channelTv_fundible.setText(channel);

        cancelBtn_fundible.setOnClickListener(v -> {
            if (denyRunnable_fundible !=null) denyRunnable_fundible.run();
            dismiss();
        });

        okBtn_fundible.setOnClickListener(v -> {
            if (addAccountRunnable_fundible !=null) addAccountRunnable_fundible.run();
            dismiss();
        });

    }


}
